package com.udata.client.activity;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.udata.client.ClientFactory;
import com.udata.client.place.DashboardPlace;
import com.udata.client.place.DocumentPlace;
import com.udata.client.place.TiebaExpPlace;
import com.udata.client.view.DashboardView;
import com.udata.client.view.DocumentView;
import com.udata.client.view.TiebaExpView;

public class DocumentActivity extends AbstractActivity implements DocumentView.Presenter {
  // Used to obtain views, eventBus, placeController
  // Alternatively, could be injected via GIN
  private ClientFactory clientFactory;
  private String        token;

  public DocumentActivity(DocumentPlace place, ClientFactory clientFactory) {
    token = place.getTokenName();
    this.clientFactory = clientFactory;
  }

  /**
   * Ask user before stopping this activity
   */
  @Override
  public String mayStop() {
    return "Please hold on. This activity is stopping.";
  }

  /**
   * Navigate to a new Place in the browser
   */
  public void goTo(Place place) {
    clientFactory.getPlaceController().goTo(place);
  }

  @Override
  public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
    DocumentView documentView = clientFactory.getDocumentView();
    documentView.setPresenter(this);
    containerWidget.setWidget(documentView.asWidget());
  }
}
